-extends 'layouts/_widget_box.haml'

-set model_name = controller.model_name
-set model_plural = controller.model_plural

-set widget_title = (widget_title|default("Related to " + model_name|title))

-set near_model = model.__class__.__name__
-if near_model == "System" and instance.is_biz_process
  -set near_model = "Process"

-set models = related_objects(instance)

-block widget_title
  =widget_title

-block widget_id
  related_widget

-block widget_help
  related

-block main
  #related.open
    .row-fluid
      .span12
        .tabbable
          %ul.nav.nav-tabs
            -for model in models
              -set far_model_name = model['related_model']
              -set far_table_name = far_model_name|underscore
              -set far_table_plural = far_model_name|underscore
              -set source_link = related_objects_link(instance.id, instance.__class__.__name__, far_model_name)
              %li.tab-btn{ 'class': "tab-btn text-={ far_table_name }"}
                %a{ 'href': '#related-={ far_table_name }-pane',
                    'data-toggle': 'tab',
                    'data-source': '={ source_link }',
                    'data-template': '/static/mustache/related.mustache',
                    'data-refresh-time': '60',
                    'data-object-plural': '={ far_table_plural }' }
                  %i{ 'class': "grcicon-={ far_table_name }-color" }
                  %span.collapse_tab_text
                    =far_model_name|title
                  -# FIXME: Include related object counts
                  =#{ ' ' + instance.count_other_objects(model).to_s }
    .tab-content
      -for model in models
        -set far_model_name = model['related_model']
        -set far_table_name = far_model_name|underscore
        .tab-pane{ 'id': "related-={ far_table_name }-pane" }
          Data for #{ far_model_name|title }
